# == Schema Information
# Schema version: 8
#
# Table name: feeds
#
#  id    :integer(11)   not null, primary key
#  title :string(255)   default(), not null
#  url   :string(255)   default(), not null
#  link  :string(255)   default(), not null
#

require 'rss'
require 'net'

class Feed  < ActiveRecord::Base

  include RSS
  include NET

  validates_uniqueness_of :url

  has_many :users, :through => :subscriptions
  has_many :subscriptions
  has_many :items

  validates_format_of :url, :with => %r{^\s*http://([^:/]+)(:([0-9]+))?(/.*)}

  def refresh()
    open_url(url) do |body|
      parse(body,self)
    end
    save!
  end

end
